Skip to content

Fix silent message corruption from absent/blank channel scripts (#344)#351

Open
e210 wants to merge 2 commits into
OpenIntegrationEngine:mainfrom
e210:fix/issue-344-undefined-preprocessor
Open

Fix silent message corruption from absent/blank channel scripts (#344)#351
e210 wants to merge 2 commits into
OpenIntegrationEngine:mainfrom
e210:fix/issue-344-undefined-preprocessor

Conversation

@e210

@e210 e210 commented Jul 16, 2026

Copy link
Copy Markdown

Fixes the root cause behind #344: POST /api/channels accepts a channel without <preprocessingScript>; the channel deploys "healthy" but corrupts every message to the literal string undefined on the wire.

Root cause

Two independent defects in JavaScriptUtil (full analysis in #344):

  1. JavaScriptBuilder.generateScript string-concatenates a null script into the JS wrapper, producing function doScript() { null }. compileAndAddScript caches it as a "custom" preprocessor because its body differs from the default script.
  2. executePreprocessorScripts guards results with result != null, but Rhino's Undefined is not Java nullContext.jsToJava coerces it to the string "undefined", which becomes the processed raw and flows to every destination.

Changes

  • compileAndAddScript: a null/blank script is now treated as absent — evict from the compiled-script cache and return false (all callers already handle false as "no script").
  • executePreprocessorScripts: both result checks (global + channel) now ignore Undefined, the same idiom getPostprocessorResponse already uses.
  • New JavaScriptUtilTest: 5 tests exercising the real Rhino path (TDD — each fix developed against a failing test).

Behavior change note

A user preprocessor with no return statement previously corrupted the message body to "undefined"; it now passes the message through unchanged. This is footgun-removal: returning the literal string "undefined" as content is never intentional (return ''; and return null; behave as before).

Verification

  • Full :server:test suite green.
  • E2E on the patched build (the issue's exact repro XML, MLLP sink logging raw bytes):
Channel variant Bytes on the wire (before) Bytes on the wire (after)
Issue's incomplete XML as-is \x0b undefined \x1c\r intact HL7 message

The broader ask in #344 — structural validation/normalization in POST /api/channels — is deliberately out of scope here; it deserves its own design discussion. This PR removes the data corruption.

@e210
e210 force-pushed the fix/issue-344-undefined-preprocessor branch from c0fd2d2 to 7642566 Compare July 16, 2026 07:48
@e210
e210 marked this pull request as ready for review July 16, 2026 07:50

@jonbartels jonbartels left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holding my review until I hear from the original issue reporter - https://discord.com/channels/943670759891554316/943670760461987862/1528943487163044094

Looks good at a glance, but I'll let the OP verify it first

@github-actions

Copy link
Copy Markdown

Test Results

659 tests  +5   659 ✅ +5   3m 38s ⏱️ +55s
109 suites +1     0 💤 ±0 
109 files   +1     0 ❌ ±0 

Results for commit 7642566. ± Comparison against base commit a08c114.

@MichaelLeeHobbs

Copy link
Copy Markdown

Thanks for tracking this down — clean fix, and the root cause explains a symptom I couldn't (RAW channels corrupting too, since the preprocessor runs on the raw message before datatype handling). Nice test coverage on the real Rhino path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants